package org.classg.statistics.schedule;

import org.classg.statistics.service.StatisticsDailyService;
import org.classg.statistics.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTask {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    /*@Scheduled(cron = "0/5 * * * * ?")
    public void tesk1() {
        System.out.println("我执行了！"+ DateTime.now());
    }*/

    // 在每天凌晨1点，把前一天数据进行数据查询添加
    @Scheduled(cron = "0 0 1 * * ?")
    public void tesk2() {
        // 获取上一天的日期
        String day = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        statisticsDailyService.insertStaByDay(day);
    }
}
